package com.flushbonading.controller;


import com.flushbonading.annotation.BackStage;
import com.flushbonading.annotation.PassToken;
import com.flushbonading.annotation.UserLoginToken;
import com.flushbonading.pojo.Registration;
import com.flushbonading.pojo.RespBean;
import com.flushbonading.pojo.dto.EnrollDTO;
import com.flushbonading.pojo.dto.LoginDTO;
import com.flushbonading.pojo.dto.RegistrationDTO;
import com.flushbonading.service.impl.RegistrationServiceImpl;
import com.flushbonading.util.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyx
 * @since 2021-04-07
 */
@RestController
@RequestMapping("/registration")
@BackStage
public class RegistrationController {
    @Autowired
    private RegistrationServiceImpl registrationService;
    @ResponseBody
    @GetMapping("/enroll")
    public boolean enroll(EnrollDTO enrollDTO){
        return  registrationService.enroll(enrollDTO);
    }

    @PostMapping("/all")
    public List<RegistrationDTO> getAll(){
        return registrationService.getRegistrationMessage();
    }

    @PostMapping("/delete/{student_number}")
    public RespBean delete(@PathVariable("student_number") String student_number){
        System.out.println("进入了");
        int i = registrationService.deleteRegistrationByStudentNum(student_number);
        if (i<0)
            return RespBean.error("删除失败");
        return RespBean.success("删除成功!");
    }
    @PostMapping("/updateAdmit/{student_number}/{admit}")
    public RespBean updateAdmit(@PathVariable("student_number")String student_number,@PathVariable("admit")boolean admit){
        int i = registrationService.updateAdmitByStudentNum(student_number, admit);
        if (i<0)
            return RespBean.error("提交失败");
        return RespBean.success("提交成功!");
    }

    @PostMapping("/counts")
    public int counts(){
        return registrationService.counts();
    }
    @PostMapping("/search/{student_number}")
    public List<RegistrationDTO> search(@PathVariable("student_number") String student_number){
        return registrationService.getRegistrationMessageByNum(student_number);
    }


}
